<template>
  <el-container>
    <el-header>
      <home-header/>
    </el-header>
    <el-container>
      <el-aside :width="menuWidth">
        <home-aside
          :menuList="menuList"
          ref="homeMenu"
          @changeCollapse="changeCollapse"/>
      </el-aside>
      <el-main>
        <home-main/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { HomeHeader, HomeAside, HomeMain } from './childrenCpns'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeAside,
    HomeMain
  },
  data () {
    return {
      menuList: [],
      isCollapse: false
    }
  },
  created () {
    this._getMenuList()
  },
  methods: {
    // 1. 获取菜单目录
    async _getMenuList () {
      const { data: res } = await this.$http.get('menus')
      // console.log(res)
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.message)
      }
      this.menuList = res.data
    },
    // 2. 修改isCollapse
    changeCollapse (value) {
      this.isCollapse = value
    }
  },
  computed: {
    // 1. collapse的时候修改menu的width
    menuWidth () {
      // return '200px'
      return this.isCollapse ? '64px' : '200px'
    }
  }
}
</script>

<style scoped lang="less">
.el-container {
  height: 100%;
}
.el-header {
  background-color: #333744;;
  padding-left: 0;
}
.el-aside {
  background-color: #333744;
}
.el-main {
  background-color: #eaedf1;
}
</style>
